﻿@model TopMenuModel
@using Nop.Core.Domain
@using Nop.Core.Infrastructure
@using Nop.Web.Models.Catalog;
@{
    //var isRtl = this.ShouldUseRtlTheme();
    //var supportResponsive = EngineContext.Current.Resolve<StoreInformationSettings>().ResponsiveDesignSupported;
}
@helper RenderCategoryLine(CategorySimpleModel category, int level, bool responsiveMobileMenu)
{
    var hasChildMenue = category.SubCategories.Count > 0;
    <li class="@(hasChildMenue?"dropdown-top-menu":"")">
        <a class="@(hasChildMenue?"dropdown-toggle":"")" href="@Url.RouteUrl("Category", new { SeName = category.SeName })">
            @category.Name
            @if (category.NumberOfProducts.HasValue)
            {
                <text> </text>@T("Categories.TotalProducts", category.NumberOfProducts.Value)
            }

            @if (hasChildMenue)
            {
                <span class="caret"></span>
            }
        </a>
        @{
            var levelClass = "";
            if (level == 0)
            {
                levelClass = "firstLevel";
            }
            if (hasChildMenue)
            {
                <ul class="sublist @(hasChildMenue?"dropdown-menu":"") @levelClass">
                    @foreach (var subCategory in category.SubCategories)
                    {
                        @RenderCategoryLine(subCategory, level + 1, responsiveMobileMenu)
                    }
                </ul>
            }
        }
    </li>
}

<ul id="j-narbar-top-menu" class="nav navbar-nav">
    @Html.Widget("header_menu_before")

    @foreach (var category in Model.Categories)
    {
        @RenderCategoryLine(category, 0, false)
    }
    @*@foreach (var topic in Model.Topics)
        {
            <li><a href="@Url.RouteUrl("Topic", new { SeName = topic.SeName })">@topic.Name</a></li>
        }
        @if (Model.Categories.Count == 0 && Model.Topics.Count == 0)
        {
            //no categories or topis to display? in this case let's diplay some default menu items (should we?)
            <li><a href="@Url.RouteUrl("HomePage")">@T("HomePage")</a></li>
            if (Model.RecentlyAddedProductsEnabled)
            {
                <li>
                    <a href="@Url.RouteUrl("RecentlyAddedProducts")">@T("Products.NewProducts")</a>
                </li>
            }
            <li><a href="@Url.RouteUrl("ProductSearch")">@T("Search")</a> </li>
            <li><a href="@Url.RouteUrl("CustomerInfo")">@T("Account.MyAccount")</a></li>
            if (Model.BlogEnabled)
            {
                <li><a href="@Url.RouteUrl("Blog")">@T("Blog")</a></li>
            }
            if (Model.ForumEnabled)
            {
                <li><a href="@Url.RouteUrl("Boards")">@T("Forum.Forums")</a></li>
            }
            <li><a href="@Url.RouteUrl("ContactUs")">@T("ContactUs")</a></li>
        }*@
    @Html.Widget("header_menu_after")
</ul>

<script type="text/javascript">
    seajs.use(["common/1.0.0/index", "dropdownbutton/1.0.0/index"], function (app, dropdown) {
        app(function () {
            var opts = {
                topNav: '#j-narbar-top-menu', btnSelector: '.dropdown-toggle', listSelector: '.dropdown-menu', offset: { y: 24, right_x: 0, left_x: -2 }
            };
            dropdown.dropDownButton(".dropdown-top-menu", opts);
        });
    });
</script>